<!-- 课表的页面 -->
<template>
  <div class="content_box">
    <!-- 节次 -->
    <div v-if="pageLoading">
      <sectionBox
        @listChange="listChange"
        style="margin-bottom: 100px"
        ref="sectionBox"
      ></sectionBox>
      <!-- 节次设置 -->
      <sectionSet :emu="emu" style="margin-bottom: 100px"></sectionSet>
      <!-- 课表管理 -->
      <scheduleManagement
        :emu="emu"
        @setSection="setSectionFn"
      ></scheduleManagement>
    </div>
  </div>
</template>

<script>
import {
  adminSchoolTimetablegradeList,
  adminSchoolTimetableSemesterList,
  adminSchoolTimetableGradeSubjectList
} from '@/api/lcmapi.js'
export default {
  data () {
    return {
      emu: {
        gradeList: [],
        semesterList: []
      },
      tableArr: [
        {
          prop: 'alias',
          label: '简称'
        },
        {
          prop: 'useCount',
          label: '名称'
        },
        {
          prop: 'questionCount',
          label: '说明'
        },
        {
          type: 'btnArr',
          label: '操作',
          prop: 'configBtn',
          fixed: 'right',
          width: 180
        }
      ],
      tableData: [],
      total: 0,
      currPage: 1,
      pageLoading: true
    }
  },
  components: {
    sectionBox: resolve => require(['./components/section.vue'], resolve),
    sectionSet: resolve => require(['./components/section-set.vue'], resolve),
    scheduleManagement: resolve =>
      require(['./components/schedule-management.vue'], resolve)
  },
  // 生命周期 - 创建完成（访问当前this实例）
  created () {
    this.getInit()
  },
  activated () {
    this.pageLoading = false
    this.$nextTick(() => {
      this.pageLoading = true
    })
  },
  // 生命周期 - 挂载完成（访问DOM元素）
  mounted () {},
  methods: {
    // 初始获取当前枚举
    async getInit () {
      let adminSchoolTimetablegradeListRes = await adminSchoolTimetablegradeList() // 年级
      let adminSchoolTimetableSemesterListRes = await adminSchoolTimetableSemesterList() // 学期
      let adminSchoolTimetableGradeSubjectListRes = await adminSchoolTimetableGradeSubjectList() // 科目
      let semesterList = []
      adminSchoolTimetableSemesterListRes[1].data.forEach(item => {
        semesterList.push({
          id: item.id,
          value: `${item.year}年第${this.$convertNum(item.type)}学期`
        })
      })
      this.emu = {
        gradeList: adminSchoolTimetablegradeListRes[1].data,
        semesterList: semesterList,
        sectionList: this.emu.sectionList || [],
        subject: adminSchoolTimetableGradeSubjectListRes[1].data
      }
      console.log(this.emu)
    },
    listChange (list) {
      this.emu.sectionList = list
    },
    // 沒有課表的情況
    setSectionFn () {
      this.$confirm('未添加节次，是否进入节次管理进行设置', '提示', {
        confirmButtonText: '是',
        cancelButtonText: '否',
        center: true
      })
        .then(() => {
          this.$refs.sectionBox.addSection('')
        })
        .catch(() => {})
    }
  }
}
</script>
<style lang="scss" scoped>
.content_box {
  padding: 20px 25px;
  background: #ffffff;
  border-radius: 6px;
  .h_title {
    padding: 16px 0px;
    padding-left: 20px;
    font-size: 18px;
    border-bottom: 1px #ececec solid;
  }
}
</style>
